<template>
    <el-container class="home-container">
        <!-- el-container 外层容器 -->
        <!-- 当子元素中包含 <el-header> 或 <el-footer> 时，全部子元素会垂直上下排列，否则会水平左右排列。 -->

        <!-- el-header 顶栏容器 -->
        <el-header>
            <div>
                <span>后台管理系统</span>
            </div>
            <el-button type="danger" @click="logout">退出</el-button>
        </el-header>

        <!-- el-container 布局容器 -->
        <el-container>
            <!-- el-aside 侧边栏容器 -->
            <el-aside :width="isCollapse ? '64px' : '250px'">
                <div class="toggle-button" @click="toggleClapse">展开</div>

                <!-- router 启用该模式会在激活导航时以 index 作为 path 进行路由跳转 -->
                <!-- unique-opened 是否只保持一个子菜单的展开 -->
                <!-- active-text-color 当前激活菜单的文字颜色（仅支持 hex 格式） -->
                <!-- 这几个颜色属性，都是仅支持hex 格式 -->

                <!-- collapse-transition 开启折叠动画-->
                <!-- collapse 开启折叠 -->
                <el-menu
                    background-color="#333744"
                    text-color="#fff"
                    active-text-color="#ffd04b"
                    router
                    unique-opened
                    :collapse="isCollapse"
                    :collapse-transition="false"
                >
                    <!-- index 唯一标志 -->
                    <el-submenu
                        :index="item.id + ''"
                        v-for="item in menuList"
                        :key="item.id"
                    >

                        <template slot="title">
                            <i :class="menuIcon(item.name)"></i>
                            <!--<i class="el-icon-setting"></i>-->
                            <span>{{item.name}}</span>
                        </template>

                        <el-menu-item
                            :index="subMenu.url+''"
                            v-for="subMenu in item.children"
                            :key="subMenu.id"
                        >
                            <template slot="title">
                                <i :class="menuIcon(subMenu.name)"></i>
                                <!--<i class="el-icon-setting"></i>-->
                                <span>{{subMenu.name}}</span>
                            </template>

                        </el-menu-item>

                    </el-submenu>

                </el-menu>

            </el-aside>

            <!-- el-main 主要区域容器 -->
            <el-main>
                <router-view v-if="isRouterAlive"/>
            </el-main>

        </el-container>
    </el-container>
</template>
<script>
    export default {
        data() {
            return {
                menuList: [
                    {
                        id: 1,
                        name: "用户管理",
                        children: [{id: 1, name: "用户列表", url: "/mangerList"}]
                    },
                    {
                        id: 2,
                        name: "权限管理",
                        children: [{id: 1, name: "权限列表", url: "/permission"}]
                    },
                    {
                        id: 3,
                        name: "角色管理",
                        children: [{id: 1, name: "角色列表", url: "/sysrole"}]
                    },
                    {
                        id: 4,
                        name: "影院管理",
                        children: [
                            {id: 1, name: "影厅管理", url: "/department"},
                            {id: 2, name: "座位管理", url: "/department"},
                        ]
                    },
                    {
                        id: 5,
                        name: "电影管理",
                        children: [
                            {id: 1, name: "影片管理", url: "/department"},
                            {id: 2, name: "类型管理", url: "/department"},
                            {id: 3, name: "演员管理", url: "/department"},
                            {id: 4, name: "排片管理", url: "/department"},
                        ]
                    },
                    {
                        id: 6,
                        name: "日志管理",
                        children: [
                            {id: 1, name: "操作记录", url: "/department"},
                            //这个生成文件，可能应该放在操作记录中
                            {id: 2, name: "生成文件", url: "/department"}
                        ]
                    },
                    {
                        id: 7,
                        name: "订单管理",
                        children: [
                            {id: 1, name: "已支付", url: "/department"},
                            //这个生成文件，可能应该放在操作记录中
                            {id: 2, name: "待支付", url: "/department"}
                        ]
                    },
                    {
                        id: 8,
                        name: "评论管理",
                        children: [
                            {id: 1, name: "评论管理", url: "/department"},
                        ]


                    },
                    {
                        id: 9,
                        name: "门户用户管理",
                        children: [
                            {id: 1, name: "门户用户管理", url: "/department"},
                        ]


                    },
                    {
                        id: 10,
                        name: "路由管理",
                        children: [
                            {id: 1, name: "路由列表", url: "/department"},
                        ]


                    },

                ],
                isCollapse: false,
                isRouterAlive: true,
                // menuListIcon:[
                //     "el-icon-user-solid",
                //     "el-icon-coordinate",
                //     "el-icon-magic-stick",
                //     "el-icon-video-camera-solid",
                //     "el-icon-video-camera",
                //     "el-icon-notebook-1",
                //     "el-icon-coin",
                //     "el-icon-chat-line-round"
                // ]
            };
        },
        methods: {
            menuIcon(name){
                if (name.indexOf("管理员")!=-1){
                    return "el-icon-user-solid"
                }
                if (name.indexOf("权限")!=-1){
                    return "el-icon-coordinate"
                }
                if (name.indexOf("角色")!=-1){
                    return "el-icon-magic-stick"
                }
                if (name.indexOf("影院")!=-1){
                    return "el-icon-video-camera-solid"
                }
                if (name.indexOf("影厅")!=-1){
                    return "el-icon-s-platform"
                }
                if (name.indexOf("电影")!=-1){
                    return "el-icon-video-camera"
                }
                if (name.indexOf("演员")!=-1){
                    return "el-icon-user"
                }
                if (name.indexOf("评论")!=-1){
                    return "el-icon-chat-line-round"
                }
                if (name.indexOf("排片")!=-1){
                    return "el-icon-notebook-1"
                }
                if (name.indexOf("订单")!=-1){
                    return "el-icon-coin"
                }
                if (name.indexOf("用户")!=-1){
                    return "el-icon-s-custom\n"
                }
            },
            reload() {
                this.isRouterAlive = false;
                this.$nextTick(function () {
                    this.isRouterAlive = true;
                });
            },
            toggleClapse() {
                this.isCollapse = !this.isCollapse;
            },
            logout() {
                window.sessionStorage.clear();
                this.$router.push("/login");
            },
            loadMenus() {
                let userCode = sessionStorage.getItem("userCode");
                // console.log("userCode=" + userCode);
                this.$api.login.getMyRole(userCode)
                    .then(res => {
                        // console.log(res.data.data);
                        this.menuList = res.data.data;
                });
            }
        },
        created() {
            this.loadMenus();
        }
    };
</script>
<style lang="less" scoped>

    .toggle-button {
        background-color: #480a06;
        font-size: 10px;
        text-align: center;
        color: #fff;
        letter-spacing: 0.2em;

        /*设置鼠标样式*/
        cursor: pointer;
    }

    .el-header {
        background-color: #373d41;

        /*flex 容器*/
        display: flex;

        /*在弹性盒对象的 <div> 元素中的各项周围留有空白，与display: flex; */
        justify-content: space-between;
        /* space-between  项目位于各行之间留有空白的容器内。 */

        padding-left: 0;
        align-items: center;
        color: #fff;
        font-size: 22px;
        > div {
            display: flex;
            align-items: center;
            margin-left: 30px;
            img {
                width: 30px;
                height: 30px;
            }
            span {
                margin-left: 14px;
            }
        }
    }

    .el-aside {
        background-color: #333744;
        text-align: center;
        .el-menu {
            border-right: 0;
            .el-submenu{
                .el-menu-item{
                    text-align: right;
                }
            }
        }
    }

    .el-main {
        background-color: #eaedf1;
    }

    .home-container {
        height: 100%;
    }
</style>